﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Globalization;
using System.Web.Security;

namespace lnxsj.web.Recruitment.Models
{


    public class User
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int Id { set; get; }

        [Required]
        [Display(Name = "登录名")]
        [MaxLength(20)]
        public string 登录名 { set; get; }

        [Required]
        [MaxLength(20)]
        [Display(Name = "显示名")]
        public string 显示名 { set; get; }

        [MaxLength(50), Display(Name = "备注")]
        public string 备注 { set; get; }
    }


    public class LoginModel
    {
        [Required]
        [Display(Name = "用户名")]
        public string UserName { get; set; }

        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "密码")]
        public string Password { get; set; }

        [Display(Name = "记住我?")]
        public bool RememberMe { get; set; }
    }

    public class RegisterModel
    {
        [Required]
        [Display(Name = "用户名")]
        public string UserName { get; set; }

        [MaxLength(20)]
        [Display(Name = "显示名")]
        public string 显示名 { set; get; }

        [Required]
        [StringLength(100, ErrorMessage = "{0} 必须至少包含 {2} 个字符。", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "密码")]
        public string Password { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "确认密码")]
        [Compare("Password", ErrorMessage = "密码和确认密码不匹配。")]
        public string ConfirmPassword { get; set; }

        [Required]
        [Display(Name = "备注")]
        public string 备注 { get; set; }
    }

    public class ChangePasswordModel
    {

        [StringLength(100, ErrorMessage = "{0} 必须至少包含 {2} 个字符。", MinimumLength = 6)]
        [DataType(System.ComponentModel.DataAnnotations.DataType.Password)]
        [Display(Name = "密码")]
        public string OldPassword { set; get; }

        [Required]
        [StringLength(100, ErrorMessage = "{0} 必须至少包含 {2} 个字符。", MinimumLength = 6)]
        [DataType(System.ComponentModel.DataAnnotations.DataType.Password)]
        [NoCompare("OldPassword",ErrorMessage = "旧密码和新密码相同。")]

        [Display(Name = "密码")]
        public string Password { set; get; }


        [DataType(DataType.Password)]
        [Display(Name = "确认密码")]
        [Compare("Password", ErrorMessage = "密码和确认密码不匹配。")]
        public string ConfirmPassword { get; set; }

    }
    //
    /// <summary>
    /// 验证不相同
    /// </summary>
    public class NoCompareAttribute:CompareAttribute{

        public NoCompareAttribute(string otherProperty) : base(otherProperty) { }

        protected override ValidationResult IsValid(object value, ValidationContext validationContext){
            var _vr =  base.IsValid(value, validationContext);
            if (_vr == ValidationResult.Success)
            {
                return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
            }
            else {
                return ValidationResult.Success;
            }

        }
    }


}
